// pkg_doctors/pages/healthData/healthData.js
let wxCharts = require('../../../utils/wxcharts.js');
import request from '../../../utils/http.js'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    use_date_arr:[],
    countDay:0,

    tjr_id:0,
    personId:0,
    dianPuId:0,

    title: ["健康数据","会员权益", "服务包", "24小时医生","AI智能问诊","舌面诊","检测报告","每日打卡"],
    currentTab: 0,
    left: "",
    winHeight: 0,
    windowWidth: 320,

    guid: '',
    name: '',
    sex: '',
    age:'',
    jiuZhenRenShenFenZhengHao: '',
    xy: '',
    tw: '',
    zyysSign: '',
    ns: '',
    xd: '',
    xueya1: '',
    xueya2: '',
    zdgc: '',
    rzstat: '',
    sjyySign: '',
    xt: '',
    updateDate: '',

    twDate: [],
    twValue: [],

    nsDate: [],
    nsValue: [],

    fwbList:[],
    fwbListLength:0,

    xy_zhuangTai:2,
    tw_zhuangTai:2,
    ns_zhuangTai:2,
    xd_zhuangTai:2,
    xueya1_zhuangTai:2,
    xueya2_zhuangTai:2,
    zdgc_zhuangTai:2,
    xt_zhuangTai:2,

    ys_recordlist:[],
    ys_page:1,
    ys_maxPage:1,
    ys_maxPageFlage:false,

    ai_recordlist:[],
    ai_page:1,
    ai_maxPage:1,
    ai_maxPageFlage:false,

    img_recordlist:[],
    img_page:1,
    img_maxPage:1,
    img_maxPageFlage:false,

    rep_recordlist:[],
    rep_page:1,
    rep_maxPage:1,
    rep_maxPageFlage:false,

    quanYiList:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.changeline();
    var that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          // winHeight: res.windowHeight - (296 / 750 * res.windowWidth),
          winHeight: res.windowHeight - (100 / 750 * res.windowWidth),
          windowWidth: res.windowWidth
        });
      }
    });

    that.setData({
      guid: options.guid,
      tjr_id: (options.tjr_id == '' || options.tjr_id == undefined) ? wx.getStorageSync(app.globalData.TJR_ID) : options.tjr_id,
      personId: wx.getStorageSync(app.globalData.PERSON_ID),
      dianPuId: (options.dianPuId == '' || options.dianPuId == undefined) ? (wx.getStorageSync(app.globalData.SHOPID) > 0 ? wx.getStorageSync(app.globalData.SHOPID) : 1) : options.dianPuId,
    })


    var startMouthDate
    var date = new Date()
    var yearStr=date.getFullYear()

    var zero = '0'
    var mouthStr = date.getMonth() + 1

    if (mouthStr < 10) {
      mouthStr = zero.concat(mouthStr)
    }
    startMouthDate=yearStr+'-'+mouthStr+'-01'

    that.getDakaDayList(startMouthDate);




    wx.setStorageSync(app.globalData.SHOPID, that.data.dianPuId)
    wx.setStorageSync(app.globalData.TJR_ID, that.data.tjr_id)

    that.searchByGuid();
    that.getVipItemList();
  },

  //根据guid,获取档案详情
  searchByGuid: function () {

    var that = this

    if (that.data.guid != '') {
      let data = {
        patientUniqueGuid: that.data.guid,
      }
      request.get('jianKangDangAn/getOneJiuZhenRenInfo', data, res => {
        // console.log("个人档案数据:" + JSON.stringify(res))

        if(res.statusCode==200){
          that.setData({
            name: res.data.name,
            sex: res.data.sex,
            jiuZhenRenShenFenZhengHao: res.data.jiuZhenRenShenFenZhengHao,
            xy: res.data.xy==null?'--': res.data.xy,
            tw: res.data.tw==null?'--': res.data.tw,
            zyysSign: res.data.zyysSign==null?'--': res.data.zyysSign,
            ns: res.data.ns==null?'--': res.data.ns,
            xd: res.data.xd==null?'--': res.data.xd,
            xueya1: res.data.xueya1==null?'--': res.data.xueya1,
            xueya2: res.data.xueya2==null?'--': res.data.xueya2,
            zdgc: res.data.zdgc==null?'--': res.data.zdgc,
            rzstat: res.data.rzstat,
            sjyySign: res.data.sjyySign==null?'--': res.data.sjyySign,
            xt: res.data.xt==null?'--': res.data.xt,
            updateDate: res.data.updateDate,
            age:res.data.age==null?'--': res.data.age,
            xy_zhuangTai:res.data.xy_zhuangTai,
            tw_zhuangTai:res.data.tw_zhuangTai,
            ns_zhuangTai:res.data.ns_zhuangTai,
            xd_zhuangTai:res.data.xd_zhuangTai,
            xueya1_zhuangTai:res.data.xueya1_zhuangTai,
            xueya2_zhuangTai:res.data.xueya2_zhuangTai,
            zdgc_zhuangTai:res.data.zdgc_zhuangTai,
            xt_zhuangTai:res.data.xt_zhuangTai,
          })

          that.getTw();
          that.getXy();
          that.getXt();
          that.getNs();
          that.getZdgc();
          that.getXd();
          that.getXueyang();


      }else{
        wx.showToast({
          title: '获取数据失败', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 2000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      }

      }, err => {
        wx.showToast({
          title: '获取信息失败', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      })
    }

  },


   //打卡
   getDakaDayList:function(startMouthDate){
    var that=this


    let data = {
      guid: that.data.guid,
      startMouthDate: startMouthDate
    }

    request.get('dakaIndex/getMouthDakaIndexList', data, res => {
      // console.log("打卡:" + JSON.stringify(res))

      that.setData({
        use_date_arr:res.data.list,
        countDay:res.data.countDay
      })

  

    }, err => {
      wx.showToast({
        title: '获取信息失败', // 提示的内容
        icon: "none", // 图标，默认success
        duration: 1000, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿透
      })
    })

  },


  //获取我的权益
  getVipItemList:function(){
    var that = this

    let data = {
      guid: that.data.guid,
    }

    request.get('huiYuanKa/getHuiYuanQuanYi', data, res => {
      
      // console.log("我的权益:" + JSON.stringify(res))

      if(res.statusCode==200){  
          that.setData({
          quanYiList:res.data.listChanPin
          })
      }

      that.getFWB();
      wx.hideLoading();
    
    }, err => {
      wx.showToast({
        title: '处理失败，请联系技术人员', // 提示的内容
        icon: "none", // 图标，默认success
        duration: 1000, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿透
      })
      wx.hideLoading();
    })


  },
  
  
  //查询名下服务包
  getFWB:function(){
    var that = this

    if (that.data.guid != '') {
      let data = {
        jiuZhenRenGuid: that.data.guid,
      }

      request.get('fuWuBaoOrderForm/jiuZhenRenFuWuBaoOrderFormList', data, res => {
        // console.log("服务包:" + JSON.stringify(res.data))

          that.setData({
            fwbList:res.data,
            fwbListLength:res.data.length

          })

          that.getYsHuorsData();


      }, err => {
        wx.showToast({
          title: '获取信息失败', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      })
    }

  },



  //获取24小时医生
  getYsHuorsData(){

    var that = this
    if (that.data.ys_maxPageFlage == false) {
      wx.showLoading({
        title: '加载中...',
        mask: true
      })
  
      let data = {
        patient_unique_guid: that.data.guid,
        datatype:'zyys',
        pageSize:10,
        page:that.data.ys_page
      }
  
      request.get('jianKangDangAn/getJianKangDangAnAll', data, res => {
          // console.log("24小时医生:"+that.data.ys_page+"||" + JSON.stringify(res.data))
        wx.hideLoading();
       
        that.getAiYsData();
        if(res.data.code==200){
          that.setData({
            ys_recordlist:that.data.ys_page==1?res.data.data.recordlist:that.data.ys_recordlist.concat(res.data.data.recordlist),
            ys_page:that.data.ys_page+1,
            ys_maxPage:res.data.data.pageNum
          })
        }


  
        if(that.data.ys_page>that.data.ys_maxPage){
          that.setData({
            ys_maxPageFlage:true,
          })
        }
      
      }, err => {
        wx.showToast({
          title: '处理失败，请联系技术人员', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
        wx.hideLoading();
      })
  
  
    }
    // }else{
    //   wx.showToast({
    //     title: "已经是全部数据", // 提示的内容
    //     icon: "none", // 图标，默认success
    //     duration: 1000, // 提示的延迟时间，默认1500
    //     mask: false, // 是否显示透明蒙层，防止触摸穿透
    //   })
    // }
  
  },

  //获取AI问诊数据
  getAiYsData(){

    var that = this
    if (!that.data.ai_maxPageFlage) {
      wx.showLoading({
        title: '加载中...',
        mask: true
      })
  
      let data = {
        patient_unique_guid: that.data.guid,
        datatype:'znys',
        pageSize:10,
        page:that.data.ai_page
      }
  
      request.get('jianKangDangAn/getJianKangDangAnAll', data, res => {
          console.log("AI医生:"+that.data.ai_page+"||" + JSON.stringify(res.data))
        wx.hideLoading();
        that.getImgData();
        if(res.data.code==200){
          that.setData({
            ai_recordlist:that.data.ai_page==1?res.data.data.recordlist:that.data.ai_recordlist.concat(res.data.data.recordlist),
            ai_page:that.data.ai_page+1,
            ai_maxPage:res.data.data.pageNum
          })
        }


  
        if(that.data.ai_page>that.data.ai_maxPage){
          that.setData({
            ai_maxPageFlage:true,
          })
        }
      
      }, err => {
        wx.showToast({
          title: '处理失败，请联系技术人员', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
        wx.hideLoading();
      })
  
  
    }
    // }else{
    //   wx.showToast({
    //     title: "已经是全部数据", // 提示的内容
    //     icon: "none", // 图标，默认success
    //     duration: 1000, // 提示的延迟时间，默认1500
    //     mask: false, // 是否显示透明蒙层，防止触摸穿透
    //   })
    // }
  
  },

  //获取舌诊数据
  getImgData(){

    var that = this
    if (that.data.img_maxPageFlage == false) {
      wx.showLoading({
        title: '加载中...',
        mask: true
      })
  
      let data = {
        patient_unique_guid: that.data.guid,
        datatype:'zysz',
        pageSize:10,
        page:that.data.img_page
      }
  
      request.get('jianKangDangAn/getJianKangDangAnAll', data, res => {
          // console.log("舌诊:"+that.data.img_page+"||" + JSON.stringify(res.data))
        wx.hideLoading();
       
        that.getReportData();
        if(res.data.code==200){
          that.setData({
            img_recordlist:that.data.img_page==1?res.data.data.recordlist:that.data.img_recordlist.concat(res.data.data.recordlist),
            img_page:that.data.img_page+1,
            img_maxPage:res.data.data.pageNum
          })
        }


  
        if(that.data.img_page>that.data.img_maxPage){
          that.setData({
            img_maxPageFlage:true,
          })
        }
      
      }, err => {
        wx.showToast({
          title: '处理失败，请联系技术人员', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
        wx.hideLoading();
      })
  
    }
  
    // }else{
    //   wx.showToast({
    //     title: "已经是全部数据", // 提示的内容
    //     icon: "none", // 图标，默认success
    //     duration: 1500, // 提示的延迟时间，默认1500
    //     mask: false, // 是否显示透明蒙层，防止触摸穿透
    //   })
    // }
  
  },


   //获取报告
   getReportData(){

    var that = this
    if (that.data.rep_maxPageFlage == false) {
      wx.showLoading({
        title: '加载中...',
        mask: true
      })
  
      let data = {
        patient_unique_guid: that.data.guid,
        datatype:'xd',
        pageSize:10,
        page:that.data.rep_page
      }
  
      request.get('jianKangDangAn/getJianKangDangAnAll', data, res => {
          // console.log("心电报告:"+that.data.rep_page+"||" + JSON.stringify(res.data))
        wx.hideLoading();
       
        if(res.data.code==200){
          that.setData({
            rep_recordlist:that.data.rep_page==1?res.data.data.recordlist:that.data.rep_recordlist.concat(res.data.data.recordlist),
            rep_page:that.data.rep_page+1,
            rep_maxPage:res.data.data.pageNum
          })
        }


  
        if(that.data.rep_page>that.data.rep_maxPage){
          that.setData({
            rep_maxPageFlage:true,
          })
        }
      
      }, err => {
        wx.showToast({
          title: '处理失败，请联系技术人员', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
        wx.hideLoading();
      })
  
    }
  
    // }else{
    //   wx.showToast({
    //     title: "已经是全部数据", // 提示的内容
    //     icon: "none", // 图标，默认success
    //     duration: 1000, // 提示的延迟时间，默认1500
    //     mask: false, // 是否显示透明蒙层，防止触摸穿透
    //   })
    // }
  
  },

  //前往服务包详情
  toFWBInfo(e){
    var fuWuBaoOrderFormId=e.currentTarget.dataset.id

    wx.navigateTo({
      url: '/pkg_index/pages/healthInfoFWB/healthInfoFWB?fuWuBaoOrderFormId='+fuWuBaoOrderFormId,
    })
  },

  
  //查看报告
  toPdfInfo(e){

    var index = e.currentTarget.dataset.index;

    var that=this
    wx.showLoading({
      title: '加载中...',
      mask: true
    })

    if(that.data.rep_recordlist[index].VALUE6!=''){
      wx.downloadFile({
        // 示例 url，并非真实存在
        url: that.data.rep_recordlist[index].VALUE6,
        success: function (res) {
          const filePath = res.tempFilePath
          wx.openDocument({
            filePath: filePath,
            success: function (res) {
              console.log('打开文档成功')
            }
          })
          wx.hideLoading();
        }
      })
    }else{
       wx.showToast({
        title: "pdf报告未生成", // 提示的内容
        icon: "none", // 图标，默认success
        duration: 1000, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿透
      })
    }


  },


  //体温
  getTw: function () {

    var that = this

    if (that.data.guid != '') {

      let data = {
        patientUniqueGuid: that.data.guid,
        datatype: 'tw'
      }

      request.get('jianKangDangAn/chaXunOneJiuZhenRenJianCeShuJu', data, res => {
        // console.log("tw:" + JSON.stringify(res.data))

        if (res.data.code == 200 && res.data.data.length>0 ) {
          var twDateTemp = [];
          var twValueTemp = [];
          res.data.data.forEach((item, index) => {
            twDateTemp.push(item.CRTDAT.substr(5, 5));
            twValueTemp.push(item.VALUE1)
          })


          // 体温
          new wxCharts({
            canvasId: 'cvs_weight',
            dataPointShape: "circle",
            type: 'line',
            extra: {
              lineStyle: 'curve' //线条的形状（弧形）
            },
            categories: twDateTemp,
            series: [{
              name: '体温',
              color: '#2998FF',
              data: twValueTemp, //设置某一个值为null会出现断层
              format: function (val) {
                return val.toFixed(0);
              }
            }],
            xAxis: {
              disableGrid: true,
            },
            yAxis: {
              format: function (val) {
                return val.toFixed(0);
              },
              fontColor: "#2998FF",
              min: 35,
              gridColor: "#f3f7f7",
              disabled: false,
            },
            width: that.data.windowWidth - 30,
            height: 200,
            dataLabel: false
          });

        }
      }, err => {
        wx.showToast({
          title: '获取信息失败', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      })

    }


  },

  //血压
  getXy: function () {

    var that = this
    if (that.data.guid != '') {
      let data = {
        patientUniqueGuid: that.data.guid,
        datatype: 'xy'
      }

      request.get('jianKangDangAn/chaXunOneJiuZhenRenJianCeShuJu', data, res => {
        // console.log("xy:" + JSON.stringify(res.data))
        if (res.data.code == 200 && res.data.data.length>0){

          var dateTemp = [];
          var valueTemp1 = [];
          var valueTemp2 = [];
          res.data.data.forEach((item, index) => {
            dateTemp.push(item.CRTDAT.substr(5, 5));
            valueTemp1.push(item.VALUE1);
            valueTemp2.push(item.VALUE2);
          })



          new wxCharts({
            canvasId: 'cvs_bloodP',
            dataPointShape: "circle",
            type: 'line',
            extra: {
              lineStyle: 'curve' //线条的形状（弧形）
            },
            categories: dateTemp,
            series: [{
              name: '收缩压',
              color: '#FFBC1A',
              data: valueTemp1, //设置某一个值为null会出现断层
              format: function (val) {
                return val.toFixed(0);
              }
            }, {
              name: '舒张压',
              color: '#29D4FF',
              data: valueTemp2, //设置某一个值为null会出现断层
              format: function (val) {
                return val.toFixed(0);
              }
            }],
            xAxis: {
              disableGrid: true,
            },
            yAxis: {
              format: function (val) {
                return val.toFixed(0);
              },
              fontColor: "#FFBC1A",
              min: 0,
              gridColor: "#f3f7f7",
              disabled: false,
            },
            width: that.data.windowWidth - 30,
            height: 200,
            dataLabel: false
          });


        }


      }, err => {
        wx.showToast({
          title: '获取信息失败', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      })
    }
  },

  //血氧
  getXueyang: function () {

    var that = this
    if (that.data.guid != '') {
      let data = {
        patientUniqueGuid: that.data.guid,
        datatype: 'xueyang'
      }

      request.get('jianKangDangAn/chaXunOneJiuZhenRenJianCeShuJu', data, res => {
        // console.log("xueyang:" + JSON.stringify(res.data))

        if (res.data.code == 200 && res.data.data.length>0){
          var dateTemp = [];
          var valueTemp = [];
          res.data.data.forEach((item, index) => {
            dateTemp.push(item.CRTDAT.substr(5, 5));
            valueTemp.push(item.VALUE1)
          })



          new wxCharts({
            canvasId: 'cvs_bloodO',
            dataPointShape: "circle",
            type: 'line',
            extra: {
              lineStyle: 'curve' //线条的形状（弧形）
            },
            categories: dateTemp,
            series: [{
              name: '血氧',
              color: '#5A6AFF',
              data: valueTemp, //设置某一个值为null会出现断层
              format: function (val) {
                return val.toFixed(0);
              }
            }],
            xAxis: {
              disableGrid: true,
            },
            yAxis: {
              format: function (val) {
                return val.toFixed(0);
              },
              fontColor: "#5A6AFF",
              min: 80,
              gridColor: "#f3f7f7",
              disabled: false,
            },
            width: that.data.windowWidth - 30,
            height: 200,
            dataLabel: false
          });




        }

      }, err => {
        wx.showToast({
          title: '获取信息失败', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      })
    }
  },

  //血糖
  getXt: function () {

    var that = this
    if (that.data.guid != '') {
      let data = {
        patientUniqueGuid: that.data.guid,
        datatype: 'xt'
      }

      request.get('jianKangDangAn/chaXunOneJiuZhenRenJianCeShuJu', data, res => {
        // console.log("xt:" + JSON.stringify(res.data))

        if (res.data.code == 200 && res.data.data.length>0){
          var dateTemp = [];
          var valueTemp = [];
          res.data.data.forEach((item, index) => {
            dateTemp.push(item.CRTDAT.substr(5, 5));
            valueTemp.push(item.VALUE1)
          })


          //血糖
          new wxCharts({
            canvasId: 'cvs_bloodS',
            dataPointShape: "circle",
            type: 'line',
            extra: {
              lineStyle: 'curve' //线条的形状（弧形）
            },
            categories: dateTemp,
            series: [{
              name: '血糖',
              color: '#EB75B7',
              data: valueTemp, //设置某一个值为null会出现断层
              format: function (val) {
                return val.toFixed(0);
              }
            }],
            xAxis: {
              disableGrid: true,
            },
            yAxis: {
              format: function (val) {
                return val.toFixed(0);
              },
              fontColor: "#EB75B7",
              min: 0,
              gridColor: "#f3f7f7",
              disabled: false,
            },
            width: that.data.windowWidth - 30,
            height: 200,
            dataLabel: false
          });


        }





      }, err => {
        wx.showToast({
          title: '获取信息失败', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      })
    }
  },

  //尿酸
  getNs: function () {
    var that = this
    if (that.data.guid != '') {
      let data = {
        patientUniqueGuid: that.data.guid,
        datatype: 'ns'
      }

      request.get('jianKangDangAn/chaXunOneJiuZhenRenJianCeShuJu', data, res => {
        // console.log("Ns:" + JSON.stringify(res.data))
        if (res.data.code == 200 && res.data.data.length>0){

          var dateTemp = [];
          var valueTemp = [];
          res.data.data.forEach((item, index) => {
            dateTemp.push(item.CRTDAT.substr(5, 5));
            valueTemp.push(item.VALUE1)
          })

          //尿酸
          new wxCharts({
            canvasId: 'cvs_uricAcid',
            dataPointShape: "circle",
            type: 'line',
            extra: {
              lineStyle: 'curve' //线条的形状（弧形）
            },
            categories: dateTemp,
            series: [{
              name: '尿酸',
              color: '#15E577',
              data: valueTemp, //设置某一个值为null会出现断层
              format: function (val) {
                return val.toFixed(0);
              }
            }],
            xAxis: {
              disableGrid: true,
            },
            yAxis: {
              format: function (val) {
                return val.toFixed(0);
              },
              fontColor: "#15E577",
              min: 100,
              gridColor: "#f3f7f7",
              disabled: false,
            },
            width: that.data.windowWidth - 30,
            height: 200,
            dataLabel: false
          });
        }

      }, err => {
        wx.showToast({
          title: '获取信息失败', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      })
    }
  },

  //总胆固醇
  getZdgc: function () {
    var that = this
    if (that.data.guid != '') {
      let data = {
        patientUniqueGuid: that.data.guid,
        datatype: 'zdgc'
      }

      request.get('jianKangDangAn/chaXunOneJiuZhenRenJianCeShuJu', data, res => {
        // console.log("zdgc:" + JSON.stringify(res.data))
        if (res.data.code == 200 && res.data.data.length>0){
          var dateTemp = [];
          var valueTemp = [];
          res.data.data.forEach((item, index) => {
            dateTemp.push(item.CRTDAT.substr(5, 5));
            valueTemp.push(item.VALUE1)
          })


          new wxCharts({
            canvasId: 'cvs_cholestero',
            dataPointShape: "circle",
            type: 'line',
            extra: {
              lineStyle: 'curve' //线条的形状（弧形）
            },
            categories: dateTemp,
            series: [{
              name: '总胆固醇',
              color: '#FF8620',
              data: valueTemp, //设置某一个值为null会出现断层
              format: function (val) {
                return val.toFixed(0);
              }
            }],
            xAxis: {
              disableGrid: true,
            },
            yAxis: {
              format: function (val) {
                return val.toFixed(1);
              },
              fontColor: "#FF8620",
              min: 1,
              gridColor: "#f3f7f7",
              disabled: false,
            },
            width: that.data.windowWidth - 30,
            height: 200,
            dataLabel: false
          });
        }

      }, err => {
        wx.showToast({
          title: '获取信息失败', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      })
    }
  },


  //心电
  getXd: function () {
    var that = this
    if (that.data.guid != '') {
      let data = {
        patientUniqueGuid: that.data.guid,
        datatype: 'xd'
      }

      request.get('jianKangDangAn/chaXunOneJiuZhenRenJianCeShuJu', data, res => {
        // console.log("xd:" + JSON.stringify(res.data))
        if (res.data.code == 200 && res.data.data.length>0){
          var dateTemp = [];
          var valueTemp = [];
          res.data.data.forEach((item, index) => {
            dateTemp.push(item.CRTDAT.substr(5, 5));
            valueTemp.push(item.VALUE1)
          })


          //心率
          new wxCharts({
            canvasId: 'cvs_heartRate',
            dataPointShape: "circle",
            type: 'line',
            extra: {
              lineStyle: 'curve' //线条的形状（弧形）
            },
            categories: dateTemp,
            series: [{
              name: '心率',
              color: '#A23FFF',
              data: valueTemp, //设置某一个值为null会出现断层
              format: function (val) {
                return val.toFixed(0);
              }
            }],
            xAxis: {
              disableGrid: true,
            },
            yAxis: {
              format: function (val) {
                return val.toFixed(0);
              },
              fontColor: "#A23FFF",
              min: 40,
              gridColor: "#f3f7f7",
              disabled: false,
            },
            width: that.data.windowWidth - 30,
            height: 200,
            dataLabel: false
          });
        }

      }, err => {
        wx.showToast({
          title: '获取信息失败', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      })
    }
  },

  
 


   //产品分组切换
   onTabsChange(e){

    var index = e.detail.value;

    if(index!=this.data.currentTab){
      // console.log("index11:" + index)
      this.setData({
        currentTab:index
      })
      // this.getSwitch(index)
    }


  },

  //产品分组切换
  swichNav(e){
 
   
     var index = e.detail.current
     

      if(index!=this.data.currentTab){
        // console.log("index22:" + index)
        this.setData({
          currentTab:index
        })
        // this.getSwitch(index)
      }
    

  },

  getSwitch(index){
    // console.log("indexWWW:"+index)

    switch(index){

      case 1:
        this.getVipItemList();
        break

     case 2:
      this.getFWB();
          break
      case 3:
        this.getYsHuorsData();
        break
      case 4:
        this.getAiYsData();
        break

      case 5:

        this.getImgData();
        break

      case 6:
        this.getReportData();
        break


      default:

    }



  },





  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: this.data.name+' 的健康档案',
      imageUrl: this.data.sex==1?'/image/man.png':'/image/woman.png',
      path: '/pkg_index/pages/healthData/healthData?tjr_id=' + this.data.personId + '&dianPuId=' + this.data.dianPuId +'&guid=' + this.data.guid 
    }
  }
})